<template>
	<view class="resume_base_info">
		<view class="title">
			<text>请填写基本信息</text>
		</view>
		<u-form :model="form" ref="uForm">
			<view class="top box">
				<u-form-item label="头像" :required="false" :right-icon="'arrow-right'">
					<c-upload :customBtn="true" :customStyle="{float:'right'}">
						<view slot="addView" class="slot_upload">
							<u-image class="camera" width="88rpx" height="88rpx" src="/static/uview/my/camera.png" />
						</view>
					</c-upload>
				</u-form-item>
				<c-input-item label="姓名" type="text" name="name" v-model="form.name" ></c-input-item>
				<c-input-item label="性别" type="radio" name="gender" v-model="form.gender" :options="genderOptions" :rightIcon="false"></c-input-item>
				<c-input-item label="出生年月" type="time" name="birth" v-model="form.birth"></c-input-item>
				<c-input-item label="民族" type="single-select" name="nation" v-model="form.nation" :options="nation"></c-input-item>
				<c-input-item label="婚姻状况" type="single-select" name="is_married" v-model="form.is_married" :options="marriedOptions"></c-input-item>
			</view>
			<view class="center box">
				<c-input-item label="身份证号" type="text" name="id_card_no" v-model="form.id_card_no"></c-input-item>
				<c-input-item label="身高" type="text" name="height" v-model="form.height"></c-input-item>
				<c-input-item label="体重" type="text" name="weight" v-model="form.weight"></c-input-item>
			</view>
			<view class="bottom box">
				<c-input-item label="现居地址" type="text" name="current_address" v-model="form.current_address"></c-input-item>
				<c-input-item label="户口所在地" type="text" name="hukou_place" v-model="form.hukou_place"></c-input-item>
			</view>
		</u-form>
		<view class="fixed_bottom_btn">
			<c-button btnType="confirm" text="保存" @click="submit">
			</c-button>
		</view>
	</view>
</template>

<script>
	import area from '../../../common/area'
	import nation from '../../../common/nation'

	const genderOptions = [{
			label: '男',
			value: "1",
		},
		{
			label: '女',
			value: "2",
		}
	];

	const marriedOptions = [{
			label: '已婚',
			value: "1",
		},
		{
			label: '未婚',
			value: "2",
		},
	];

	export default {
		data() {
			return {
				area,
				nation,
				genderOptions,
				marriedOptions,
				form: {
					name: '耿乐伟',
					gender: '',
					birth: '',
					nation: '',
					is_married: '',
					id_card_no: '',
					height: '',
					weight: '',
					current_address: '',
					hukou_place: '',
				},
				rules: {
					name: this.$u.cusTest.name,
					gender: [],
					birth: [],
					nation: [],
					is_married: [],
					id_card_no: this.$u.cusTest.idCard,
					height: [],
					weight: [],
					current_address: [],
					hukou_place: [],

				},

			};
		},

		onLoad() {
			// this.$u.api.getReruitDetails().then(res => {
			// 	this.form = res;
			// })
		},

		// 必须要在onReady生命周期，因为onLoad生命周期组件可能尚未创建完毕
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},

		methods: {

			submit() {
				console.log('submit', this.form)

				const params = {}
				if (this.form.name) {
					params.name = this.form.name
				}
				if (this.form.gender) {
					params.gender = this.form.gender
				}
				if (this.form.birth) {
					params.birth = this.form.birth
				}
				if (this.form.nation) {
					params.nation = this.form.nation
				}
				if (this.form.is_married) {
					params.is_married = this.form.is_married
				}
				if (this.form.id_card_no) {
					params.id_card_no = this.form.id_card_no
				}
				if (this.form.height) {
					params.height = this.form.height
				}
				if (this.form.weight) {
					params.weight = this.form.weight
				}
				if (this.form.current_address) {
					params.current_address = this.form.current_address
				}
				if (this.form.hukou_place) {
					params.hukou_place = this.form.hukou_place
				}

				this.$refs.uForm.validate(valid => {
					if (valid) {
						this.$u.api.editReruit(params).then(res => {
							this.$u.route({
								url: 'pages/my_sub/resume/resume',
							})
						})
					} else {
						console.log('验证失败');
					}
				});
			}
		}
	};
</script>

<style lang="scss" scoped>
	.resume_base_info {
		background: #F9F9F9;
		padding: 0 0 186rpx 0;

		.title {
			background: #FFFFFF;
			padding: 48rpx 30rpx;

			text {
				font-size: 44rpx;
				color: #333333;
				line-height: 60rpx;
			}
		}

		.box {
			background: #FFFFFF;
			margin: 0 0 16rpx 0;
			padding: 0 30rpx;
		}

		.top {
			.slot_upload {
				float: right;
				width: 96rpx;
				height: 96rpx;
				border-radius: 48rpx;
				overflow: hidden;
			}

			.camera {}
		}

		.fixed_bottom_btn {
			width: 100%;
			height: 130rpx;
			padding: 20rpx 40rpx;
			background: #FFFFFF;
			position: fixed;
			bottom: 0;
			left: 0;
			z-index: 99;
		}
	}
</style>
